package com.web.base.wechat.dao;

import com.blue.jdbc.BaseDao;
import com.web.base.wechat.model.WechatAutoMessage;
import org.springframework.stereotype.Repository;

/**
 * 微信自动回复消息数据库访问
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月27日
 */
@Repository("wechatAutoMessageDao")
public class WechatAutoMessageDao extends BaseDao<WechatAutoMessage>
{
	public WechatAutoMessageDao()
	{
	}
	
	@Override
	protected void query(StringBuilder sql, WechatAutoMessage param)
	{
		if (param != null)
		{
			if (param.getWechatId() != null && param.getWechatId() > 0)
				sql.append(" and a.wechat_id=:wechatId");
				
			if (param.getCode() != null && !param.getCode().isEmpty())
				sql.append(" and a.code=:code");
				
			if (param.getReplyType() != null)
				sql.append(" and a.reply_type=:replyType");
				
			if (param.getState() != null)
				sql.append(" and a.state=:state");
				
		}
		sql.append(" order by a.id");
	}

	@Override
	protected StringBuilder select()
	{
		StringBuilder sql = new StringBuilder(64);
		sql.append("select a.*, w.name wechat_name from wx_wechat_auto_message a");
		sql.append(" left join wx_wechat w on w.id=a.wechat_id");
		sql.append(" where 1=1");
		return sql;
	}
	
}
